package Ep06_BinaryTree.DFS.T3_0144;

import Ep06_BinaryTree.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/4/17 9:56
 * 说明：144 前序遍历  ——  递归写法
 */

public class PreOrderTraversal_recursion {
    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        preOrder(root, res);
        return res;
    }

    public void preOrder(TreeNode root, List<Integer> res){
        if (root == null){
            return;
        }
        res.add(root.val);
        preOrder(root.left, res);
        preOrder(root.right, res);
    }
}
